﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using FreightSoft.Models;

namespace FreightSoft.Controllers
{
    public class ShipmentLineController : Controller
    {
        private Entities db = new Entities();

        //
        // GET: /ShipmentLine/

        public ActionResult Index()
        {
            var shipmentlines = db.SHIPMENTLINEs.Include(s => s.SHIPMENT);
            return View(shipmentlines.ToList());
        }

        //
        // GET: /ShipmentLine/Details/5

        public ActionResult Details(decimal id = 0)
        {
            SHIPMENTLINE shipmentline = db.SHIPMENTLINEs.Find(id);
            if (shipmentline == null)
            {
                return HttpNotFound();
            }
            return View(shipmentline);
        }

        //
        // GET: /ShipmentLine/Create

        public ActionResult Create()
        {
            ViewBag.SHIPMENTID = new SelectList(db.SHIPMENTs, "SHIPMENTID", "ORIGINPORT");
            return View();
        }

        //
        // POST: /ShipmentLine/Create

        [HttpPost]
        public ActionResult Create(SHIPMENTLINE shipmentline)
        {
            if (ModelState.IsValid)
            {
                db.SHIPMENTLINEs.Add(shipmentline);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            ViewBag.SHIPMENTID = new SelectList(db.SHIPMENTs, "SHIPMENTID", "ORIGINPORT", shipmentline.SHIPMENTID);
            return View(shipmentline);
        }

        //
        // GET: /ShipmentLine/Edit/5

        public ActionResult Edit(decimal id = 0)
        {
            SHIPMENTLINE shipmentline = db.SHIPMENTLINEs.Find(id);
            if (shipmentline == null)
            {
                return HttpNotFound();
            }
            ViewBag.SHIPMENTID = new SelectList(db.SHIPMENTs, "SHIPMENTID", "ORIGINPORT", shipmentline.SHIPMENTID);
            return View(shipmentline);
        }

        //
        // POST: /ShipmentLine/Edit/5

        [HttpPost]
        public ActionResult Edit(SHIPMENTLINE shipmentline)
        {
            if (ModelState.IsValid)
            {
                db.Entry(shipmentline).State = EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            ViewBag.SHIPMENTID = new SelectList(db.SHIPMENTs, "SHIPMENTID", "ORIGINPORT", shipmentline.SHIPMENTID);
            return View(shipmentline);
        }

        //
        // GET: /ShipmentLine/Delete/5

        public ActionResult Delete(decimal id = 0)
        {
            SHIPMENTLINE shipmentline = db.SHIPMENTLINEs.Find(id);
            if (shipmentline == null)
            {
                return HttpNotFound();
            }
            return View(shipmentline);
        }

        //
        // POST: /ShipmentLine/Delete/5

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(decimal id)
        {
            SHIPMENTLINE shipmentline = db.SHIPMENTLINEs.Find(id);
            db.SHIPMENTLINEs.Remove(shipmentline);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

        protected override void Dispose(bool disposing)
        {
            db.Dispose();
            base.Dispose(disposing);
        }
    }
}